package org.eclipseuseradmin.internal.ui;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.wizard.IWizard;
import org.eclipseuseradmin.ui.wizards.INewUserWizard;

public class WizardElement {

	private final static String ATT_ID = "id";

	private final static String ATT_NAME = "name";
	
	private final static String ATT_CLASS = "class";
	
	private final static String ATT_ICON = "icon";
	
	private IConfigurationElement config;

	public WizardElement(IConfigurationElement config) {
		this.config = config;
	}
	

	public String getId() {
		return config.getAttribute(ATT_ID);
	}
	
	public String getName() {
		return config.getAttribute(ATT_NAME);
	}
	
	public INewUserWizard createWizard() {
		try {
			return (INewUserWizard) config.createExecutableExtension(ATT_CLASS);
		} catch (CoreException e) {
			return null;
		}
	}
	
	public ImageDescriptor getImageDescriptor() {

		String pluginId = config.getContributor().getName();
		String imageFilePath = config.getAttribute(ATT_ICON);
		if (imageFilePath == null) {
			return null;
		}
		return UserAdminUiPlugin.imageDescriptorFromPlugin(pluginId, imageFilePath);
	}

}
